
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何在 Nginx 中配置多站点（虚拟主机） - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何在 Nginx 中配置多站点（虚拟主机） - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Nginx 是通过什么核心配置块来实现虚拟主机（Virtual Host）功能的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Nginx 通过 `server` 块来实现虚拟主机功能，它允许在同一台服务器上使用不同的域名（或 IP 地址）托管多个网站。</div>
          </div>
          <div class="card-source">来源: 1. 虚拟主机的基本概念</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在 Nginx 中，`sites-available` 和 `sites-enabled` 这两个目录在管理虚拟主机配置时通常扮演什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`sites-available` 目录用于存放所有可用的虚拟主机配置文件。而 `sites-enabled` 目录则通过创建指向 `sites-available` 中配置文件的符号链接（symbolic link）来启用特定的虚拟主机。</div>
          </div>
          <div class="card-source">来源: 2.1. 创建配置文件</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 `server` 配置块中，`server_name`、`root` 和 `index` 这三个指令分别有什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`server_name` 用于指定虚拟主机匹配的域名；`root` 用于定义该站点的根目录，即存放网站文件的位置；`index` 用于指定默认显示的索引文件，例如 `index.html`。</div>
          </div>
          <div class="card-source">来源: 2.1. 创建配置文件</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">如何配置一个 Nginx 默认站点，以处理那些没有匹配到任何其他虚拟主机的请求？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过在 `listen` 指令中添加 `default_server` 参数，例如 `listen 80 default_server;`，并将 `server_name` 设置为下划线 `_`，即可将该 `server` 块配置为默认站点。</div>
          </div>
          <div class="card-source">来源: 3.2. 配置默认站点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">为虚拟主机启用 HTTPS 支持，需要在 `server` 块中配置哪三个关键的 SSL/TLS 指令？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">需要配置三个关键指令：1. `listen 443 ssl;` 用于在 443 端口上监听 SSL 连接；2. `ssl_certificate` 用于指定 SSL 证书文件的路径；3. `ssl_certificate_key` 用于指定证书私钥文件的路径。</div>
          </div>
          <div class="card-source">来源: 3.1. SSL/TLS 配置</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在启用一个新的 Nginx 虚拟主机配置后，推荐执行哪两个命令来安全地应用更改？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">首先使用 `sudo nginx -t` 命令来测试配置文件是否存在语法错误，确认无误后，再使用 `sudo systemctl reload nginx` 命令来重新加载 Nginx，使新的配置生效。</div>
          </div>
          <div class="card-source">来源: 2.1. 创建配置文件</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
